/*
 * Copyright (C) Michael Opitz
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
 * USA
 */
#ifndef MUSIC_HANLDER_H
#define MUSIC_HANLDER_H

#include <boost/weak_ptr.hpp>

#include "../music/music_system.h"

#include "../handler/event_handler.h"
#include "../network/network.h"

#include <list>
using namespace std;

/** 
 * \brief This namespace includes all user-specific handlers for the iRoom.
 * \author Michael Opitz
 */
namespace user_handler {
	/** 
	 * \brief This class handles all messages from music_clients.
	 */
	class music_handler : public handler::event_handler {
	public:
		/** 
		 * \brief music_handler creates a new music-handler. Don't use
		 * this constructor directly, use the create method instead.
		 * 
		 * \param s is the socket to the music-client.
		 * \param m is a pointer to the music-system.
		 */
		music_handler(boost::shared_ptr<network::i_socket> s,
				boost::shared_ptr<music::music_system> m)
		: _sock(s), _music(m) {}
		virtual ~music_handler();

		/** 
		 * \brief handle_event handles the music-events
		 * 
		 * \param n is a pointer to the received message.
		 */
		virtual void handle_event(
				boost::shared_ptr<network::message> n);

		/** 
		 * \brief create creates a new music_handler
		 * \see music_handler
		 */
		static boost::shared_ptr<user_handler::music_handler> create(
			boost::shared_ptr<network::i_socket> sock,
			boost::shared_ptr<music::music_system> m)
		{
			boost::shared_ptr<user_handler::music_handler> ptr(
				new user_handler::music_handler(sock, m));
			ptr->_this = ptr;
			return ptr;
		}
	private:
		boost::shared_ptr<network::i_socket> _sock;
		boost::shared_ptr<music::music_system> _music;
		boost::weak_ptr<user_handler::music_handler> _this;
	};
}

#endif
